package com.cykj.service.impl;

import com.cykj.mapper.VisitRecordMapper;
import com.cykj.service.VisitRecordService;
import com.cykj.util.ResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VisitRecordServiceImpl implements VisitRecordService {
    @Autowired
    private VisitRecordMapper visitRecordMapper;
    @Override
    public ResponseDto insertInfo(int adminId, String summary, String examId) {
        ////先判断该用户是否已写了体检总结
        int i = visitRecordMapper.selectByExamId(examId);
        if (i != 0){
            //说明已经写过了体检总结，那么就需要修改一下体检总结
            int i1 = visitRecordMapper.updateInfo(examId, summary);
            return new ResponseDto(2,"体检总结修改成功",null);
        }
        //其余说明该用户订单还会写入体检总结，那就进行插入数据
        //将用户得订单编号传过去获得用户的id，在进行表记录得添加
        int patientId = visitRecordMapper.selectByPatientId(examId);
        int info = visitRecordMapper.insertInfo(patientId, adminId, summary, examId);
        if (info == 0){
            return new ResponseDto(0,"添加失败",null);
        }
        visitRecordMapper.alterOrderStatus(examId);
        return new ResponseDto(1,"添加成功",null);
    }
}
